/*
 *  This file is part of WWWPal.
 *
 *  Copyright (C) 2003  Dr. John Punin, Department of Computer Science
 *  Rensselaer Polytechnic Institute
 *
 *  WWWPal is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  WWWPal is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 *  This file is part of WWWPal.
 *
 *  Copyright (C) 2003  Dr. John Punin, Department of Computer Science
 *  Rensselaer Polytechnic Institute
 *
 *  WWWPal is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  WWWPal is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#include "LOGR_independent_pages.h"

WebIndependentPagePtr
new_web_independent_page_node(void)
{
  WebIndependentPagePtr opn = (WebIndependentPagePtr)calloc(1, sizeof(WebIndependentPageStruct));
  if(!opn) {
      fprintf(stderr,"Out of Memory new_web_independent_page_node\n");
      abort();
  }
  return opn;
}

void
delete_web_independent_page_node(WebIndependentPagePtr opn)
{	
    if(!opn) return;

    if(opn->url) {
	free(opn->url); opn->url = NULL;
    }
    if(opn->mime) {
	free(opn->mime); opn->mime = NULL;
    }
    free(opn); opn = NULL;
}

void
LOGR_set_ip_num(WebIndependentPagePtr opn,int num)
{
  if(!opn) return;
  opn->num = num;
}

int
LOGR_get_ip_num(WebIndependentPagePtr opn)
{
  if(!opn) return -1;
  return opn->num;
}


void
LOGR_set_ip_url(WebIndependentPagePtr opn,char *url)
{
  if(!opn) return;
  if(!url) return;
  GRStrAllocCopy(opn->url,url);
}

const char *
LOGR_get_ip_url(WebIndependentPagePtr opn)
{
  if(!opn) return NULL;
  return opn->url;
}

void
LOGR_set_ip_mime(WebIndependentPagePtr opn,char *mime)
{
  if(!opn) return;
  if(!mime) return;
  GRStrAllocCopy(opn->mime,mime);
}

const char *
LOGR_get_ip_mime(WebIndependentPagePtr opn)
{
  if(!opn) return NULL;
  return opn->mime;
}


void
LOGR_set_ip_info(WebIndependentPagePtr opn,void *info)
{
  if(!opn) return;
  if(!info) return;
  opn->info = info;
}

void *
LOGR_get_ip_info(WebIndependentPagePtr opn)
{
  if(!opn) return NULL;
  return opn->info;
}

void
LOGR_set_ip_naccesses(WebIndependentPagePtr opn,long num)
{
  if(!opn) return;
  opn->naccesses = num;
}

void
LOGR_inc_ip_naccesses(WebIndependentPagePtr opn)
{
  if(!opn) return;
  opn->naccesses++;
}

long
LOGR_get_ip_naccesses(WebIndependentPagePtr opn)
{
  if(!opn) return 0;
  return opn->naccesses;
}

void
LOGR_set_ip_sizebytes(WebIndependentPagePtr opn,long num)
{
  if(!opn) return;
  opn->sbytes = num;
}

void
LOGR_add_ip_sizebytes(WebIndependentPagePtr opn,long num)
{
  if(!opn) return;
  opn->sbytes += num;
}

long
LOGR_get_ip_sizebytes(WebIndependentPagePtr opn)
{
  if(!opn) return 0;
  return opn->sbytes;
}

void
LOGR_set_ip_http_code(WebIndependentPagePtr opn,int http_code)
{
  if(!opn) return;
  opn->http_code = http_code;
}

int
LOGR_get_ip_http_code(WebIndependentPagePtr opn)
{
  if(!opn) return 0;
  return opn->http_code;
}

int
LOGR_is_access_ip_lower(WebIndependentPagePtr u, WebIndependentPagePtr v)
{
  return (u->naccesses < v->naccesses);
}

int
LOGR_is_access_ip_bigger(WebIndependentPagePtr u,WebIndependentPagePtr v)
{
  return(u->naccesses > v->naccesses);
}



